package com.privacy.accountmgr.utils

import android.content.Context
import android.graphics.Point
import android.view.WindowManager

object ScreenUtils {

    val screenWidth: Int
        get() {
            val wm = GlobalContext.context!!.getSystemService(Context.WINDOW_SERVICE) as WindowManager
            val p = Point()
            wm.defaultDisplay.getSize(p)
            return p.x
        }

    val screenHeight: Int
        get() {
            val wm = GlobalContext.context!!.getSystemService(Context.WINDOW_SERVICE) as WindowManager
            val p = Point()
            wm.defaultDisplay.getSize(p)
            return p.y
        }

    fun dp2px(dp: Float): Float {
        val scale = GlobalContext.context!!.getResources().getDisplayMetrics().density
        return dp * scale + 0.5f
    }

    fun px2sp(px: Float): Int {
        val scale = GlobalContext.context!!.getResources().getDisplayMetrics().scaledDensity
        return (px / scale + 0.5f).toInt()
    }

    fun sp2px(sp: Float): Float {
        val scale = GlobalContext.context!!.getResources().getDisplayMetrics().scaledDensity
        return sp * scale
    }
}